home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13842 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: druid.borland.com!usenet
  2. From: pete@borland.com (Pete Becker)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Help:what is wrong this code?
  5. Date: 10 Apr 1996 15:21:25 GMT
  6. Organization: Borland International
  7. Message-ID: <4kgjll$6lm@druid.borland.com>
  8. References: <4k3p3q$n76@brahms.udel.edu> <4k4hi3$5hm@sparcserver.lrz-muenchen.de> <Pine.ULT.3.92.960409210416.383A-100000@henson.cc.wwu.edu>
  9. NNTP-Posting-Host: pbecker.borland.com
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=ISO-8859-1
  12. X-Newsreader: WinVN 0.99.5
  13.  
  14. In article <Pine.ULT.3.92.960409210416.383A-100000@henson.cc.wwu.edu>, 
  15. n9341884@henson.cc.wwu.edu says...
  16. >
  17. >
  18. >
  19. >On 6 Apr 1996, Kurt Watzka wrote:
  20. >
  21. >> yuehong@brahms.udel.edu (Yue-hong Zheng) writes:
  22. >>
  23. >>
  24. >> >Why it give me 0.0000?
  25. >>
  26. >> >#include <stdio.h>
  27. >> >main () {
  28. >> >double a=9.008;
  29. >> >printf("%f\n",sqrt(a));
  30. >> >return 0;
  31. >> >}
  32. >
  33. >
  34. >
  35. >
  36. >your printf specifer needs to be "%lf", not "%f", since a is a double
  37. >
  38. >
  39.  
  40. No. Floats are promoted to doubles when they are passed in a variable arguments 
  41. list, as in printf, and %f is the correct format specifier. It indicates an 
  42. argument of type double. The problem is that there is no prototype for sqrt(), 
  43. so the compiler assumes that it returns an int.
  44.  
  45.